package com.fzkj.bio.part1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 服务端
 */
public class Server {

    public static void main(String[] args) {
        try {
            //
            ServerSocket ss = new ServerSocket(2323);
            System.out.println("=== 服务端启动成功 ===");
            // 等待客户端连接，程序会在这行代码阻塞
            Socket socket = ss.accept();
            // 获取输入流
            InputStream is = socket.getInputStream();
            // 获取缓冲输入字符流
            BufferedReader bis = new BufferedReader(new InputStreamReader(is));
            // 读取数据
            String msg;
            while ((msg = bis.readLine()) != null) {
                System.out.println("接收到客户端发送消息：" + msg);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }
    }

}
